<template>
  <div :class="['schoolAns', hideHeader ? 'hideHeader' : '']">
    <div class="first-words" ref="tabe" :style="stySty">页面数据加载成功</div>
    <div v-if="!noData">
      <scroller ref='scrollerBottom' style="top: 0.88rem;" :on-refresh="refresh" :on-infinite="infinite" class="my-scroller">
    
        <div class="scrollerDiv">
          <!-- 院校答疑 -->
          <ul class="questionList">
            <li class="questionItem" v-for="(item, index) of schoolsLists" :key="index" @click="jumpIntoSchools(item.id)">
              <p class="question_time">{{ (new Date(item.createTime)).format('yyyy-MM-dd hh:mm') }} 提问</p>
              <div class="question_title">{{ item.title }}</div>
              <div class="bottom">
                <span>{{ item.academyName }}</span>
                <span v-if="item.number == 0">暂无回答</span>
                <span v-else>{{ '有' + item.number + '条回答'}}</span>
              </div>
            </li>
          </ul>
        </div>
        <div style="width: 7.5rem;height: 0.5rem;"></div>
      </scroller>
    </div>
    <div v-else>
      <div class="noDataImage">
        <img src="~/static/nothing/empty_ask.png" alt="">
        <div class="describe">您还没有提问，赶紧来提问吧</div>
      </div>
    </div>
  </div>
</template>

<script>
import { academyQuestion } from "~/api/identity";
import { format } from '~/plugins/filter';
export default {
  data() {
    return {
      stySty: "",
      currentPage:1,
      noData: true,
      schoolsLists: [],
      listData_2: [],
      schoolParams: {
        pageNo: 1,
        pageSize: 10
      },
      onFetching_2: true,
    }
  },
  created() {
    if (this.commonJs.GetUrlParam('mini_token')) {
      this.hideHeader = true
    }
  },
  mounted() {
     this.$visit(this.$route.path)
    this.getSchoolsList()
  },
  methods: {
    getSchoolsList() {
      academyQuestion(this.schoolParams).then(res => {
        if (res.code == 0) {
          const data = res.data;
          this.schoolsLists = data.list;
          this.totlaPages = data.pages
          if (this.schoolsLists.length > 0) {
              this.noData = false
          } else {
              this.noData = true
          }
        } else {
          // this.$vux.toast.text('网络故障，请稍后再试~');
        }
      }).catch(error => {
        // this.$vux.toast.text('网络故障，请稍后重试~');
      }).finally(() => {
        // this.$hideLoading()
      })
    },
    jumpIntoSchools(id) {
      this.goto('/answerDetails', id);
    },
    goto(routerName, queryData) {
      this.$router.push({
        path: routerName,
        query: {
          type: queryData
        }
      });
    },
    refresh(done) {
      setTimeout(() => {
        this.schoolParams.pageNo = 1;
        this.getSchoolsList()
        this.stySty = "z-index:10000;opacity: 1;";
        let _this = this;
        setTimeout(() => {
        _this.stySty = "z-index:-1;opacity: 0;";  
        }, 2000);
        done()
      },1500)
    },
    infinite(done) {
       if (this.currentPage < this.totlaPages) {
        this.currentPage = this.currentPage + 1;
        academyQuestion({
          pageNo: this.currentPage,
          pageSize: 10,

        }).then(res => {
          if (res.code == "0") {
            const data = res.data;
            let newArr  = data.list;            
            this.schoolsLists = this.schoolsLists.concat(newArr);
            this.totlaPages = data.pages
            done();
          }
        });
      } else {
        done(true);
        return;
      }
    },
  }
}
</script>

<style lang="less" scoped>
 .first-words {
    width: 100%;
    height:  0.8rem;
    background: #ffad0d;
    position: absolute;
    z-index: -1;
    opacity: 0;
    text-align: center;
    line-height: 0.8rem;
    font-size: 0.3rem;
    color: #fff;
    left: 0;
    top: 1.9rem;
  }
  .schoolAns {
    /deep/ .pull-to-refresh-layer {
      margin-top: -0.15rem !important;
    }
    .scrollerDiv {
      padding: 0rem 0.35rem 0 0.29rem;

      .questionList {
        padding-left: 0;
        list-style: none;

        .questionItem {
          width: 100%;
          padding: 0.32rem 0;
          border-bottom: 1px solid #E5E8ED;

          .question_time {
            color: #999;
            font-size: 0.26rem;
            line-height: 0.44rem;
            margin-bottom: 0.14rem;
          }

          .question_title {
            color: #222;
            font-size: 0.3rem;
            line-height: 0.48rem;
            font-weight: bold;
            margin-bottom: 0.16rem;
          }

          .imageList {
            display: flex;
            justify-content: flex-start;
            align-items: center;
            flex-wrap: wrap;
            margin-bottom: 0.26rem;

            .imageShowItem {
              width: 1rem;
              height: 1rem;
              margin-right: 0.24rem;
              img {
                width: 100%;
                height: 100%;
              }
            }

          }

          .bottom {
            display: flex;
            justify-content: space-between;
            align-items: center;

            span {
              color: #999;
              font-size: 0.26rem;
              line-height: 0.44rem;
            }

          }

        }

      }

    }

    .noDataImage {
        text-align: center;
        padding-top: 2.4rem;
        img {
          width: 2.4rem;
          height: 2.4rem;
          margin-bottom: 0.24rem;
        }
        .describe {
          color: #999;
          font-size: 0.28rem;
          line-height: 0.4rem;
        }
        
      }
  }
  .hideHeaderTop {
    /deep/ .pull-to-refresh-layer {
      margin-top: -60px !important;
    }
  }
</style>